package com.houweishi.module.receipt.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.receipt.domain.BizReceipt;
import com.houweishi.module.receipt.service.IBizReceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库记录Controller
 * 
 * @author houweishi
 * @date 2023-02-25
 */
@RestController
@RequestMapping("/module/receipt")
public class BizReceiptController extends BaseController
{
    @Autowired
    private IBizReceiptService bizReceiptService;

    /**
     * 查询入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizReceipt bizReceipt)
    {
        startPage();
        List<BizReceipt> list = bizReceiptService.selectBizReceiptList(bizReceipt);
        return getDataTable(list);
    }

    /**
     * 导出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:export')")
    @Log(title = "入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizReceipt bizReceipt)
    {
        List<BizReceipt> list = bizReceiptService.selectBizReceiptList(bizReceipt);
        ExcelUtil<BizReceipt> util = new ExcelUtil<BizReceipt>(BizReceipt.class);
        util.exportExcel(response, list, "入库记录数据");
    }

    /**
     * 获取入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizReceiptService.selectBizReceiptById(id));
    }

    /**
     * 新增入库申请
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:add')")
    @Log(title = "入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizReceipt bizReceipt)
    {
        return toAjax(bizReceiptService.insertBizReceipt2(bizReceipt));
    }

    /**
     *  库管直接新增入库,修改库存
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:add2')")
    @Log(title = "入库记录", businessType = BusinessType.INSERT)
    @PostMapping("/post/add2")
    public AjaxResult add2(@RequestBody BizReceipt bizReceipt)
    {
        return toAjax(bizReceiptService.insertBizReceipt2(bizReceipt));
    }

    /**
     * 修改入库申请记录
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:edit')")
    @Log(title = "入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizReceipt bizReceipt)
    {
        return toAjax(bizReceiptService.updateBizReceipt3(bizReceipt));
    }

    /**
     * 同意通过采购入库申请后，修改状态和库存
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:edit2')")
    @Log(title = "入库记录", businessType = BusinessType.UPDATE)
    @PutMapping("/put/export2")
    public AjaxResult edit2(@RequestBody BizReceipt bizReceipt)
    {
        return toAjax(bizReceiptService.updateBizReceipt2(bizReceipt));
    }

    /**
     * 删除入库记录
     */
    @PreAuthorize("@ss.hasPermi('module:receipt:remove')")
    @Log(title = "入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizReceiptService.deleteBizReceiptByIds(ids));
    }
}
